package com.efast.dmom.mes.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.Bom;
import com.efast.dmom.mes.bean.BomTree;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.BomService;

import io.swagger.annotations.ApiOperation;

/**
 * to achieve the bom's new, delete, modify, query methods
 * @author WJ
 * @data 2020/2/19
 *
 */
@Controller
@RequestMapping("/bom")
public class BomController {
	
	@Autowired
	private BomService bomService;
	
	@RequestMapping(value = "/operateToBasicByBom")
	public @ResponseBody ResultBean OperateToBasicByBom(@RequestBody Bom bom) {
		
		// Determine the new
		if (bom.getModificationFlag() == IModificationFlags.NEW) {
			return bomService.save(bom);
			// Judge update
		} else if (bom.getModificationFlag() == IModificationFlags.MODIFIED) {
			return bomService.update(bom);
			// Judge to delete
		} else if (bom.getModificationFlag() == IModificationFlags.DELETED) {
			return bomService.delete(bom);
		}
		return null;
	}
	
	@RequestMapping(value = "/getBomByNameAndRevision")
	public @ResponseBody Bom getBomByNameAndRevision(@RequestBody Bom bom) {
//		return bomService.getBomByNameAndRevision(bom.getInnerEntity().getName(), bom.getInnerEntity().getRevision());
		
		return null;
	}
	
	@RequestMapping(value = "/getById/{id}")
	public @ResponseBody Bom getById(@PathVariable long id) {
		return bomService.getById(id);
	}
	
	@ApiOperation(value = "初始化Bom树对象")
	@RequestMapping(value = "/getAllBom")
	public @ResponseBody BomTree getAllBom(@RequestBody Bom bom) {
		return bomService.getAllBomByCondition(bom);
	}
	
	
	

}
